<!--
- Author:  lalala.
- Date:    2018/11/8 02.
- File:    modifymobile.
-->
<template>
  <div class="Web_Box">
    <div @click="back" class="Topmenu"><i class="iconfont icon-youjiantou"><a href=""></a></i>
      <h1>修改绑定手机</h1>
      <span></span>
    </div>
    <div class="login_dl">
      <div class="login_ipt1">
        <i class="iconfont icon-denglu_shoujihao1"></i><input type="number" v-model="mobile" placeholder="输入新手机号">
        <span style="width: 120px;">
          <message-code type="2" :tel="mobile"  :callback="handleMessageCode"></message-code>
        </span>
      </div>
      <div class="login_ipt1">
        <i class="iconfont icon-wangjimima_xinmima"></i><input type="password" v-model="password" placeholder="输入登录密码">
      </div>
      <div class="login_ipt1">
        <i class="iconfont icon-wangjimima_yanzhengma"></i><input type="number" v-model="code" placeholder="输入验证码">
      </div>
    </div>
    <div class="login_btn1" style="padding: 3rem 10px;">
      <span @click="submitNewMobile">完成</span>
    </div>
  </div>
</template>

<script>
  import {mapModules, mapRules} from 'vuet'
  import messageCode from '../../components/message-code.vue'
  export default{
    mixins: [
      mapModules({memberInfo: 'memberInfo'}),
      mapRules({once: 'memberInfo'})
    ],
    data() {
      return {
        code: '',
        mobile: '',
        password: '',
        checkPassword: '',
        member_id: this.$route.params.member_id
      }
    },
    components: {
      'message-code': messageCode
    },
    created() {
      console.log(this.$route.params.member_id)
    },
    methods: {
      back() {
        this.$router.go(-1)
      },
      handleMessageCode(code) {
        this.check_mobile = code
      },
      submitNewMobile() {
        var postData = {}
        postData.code = this.code
        postData.mobile = this.mobile
        postData.password = this.password
        if (!this.$validator.phone(this.mobile)) {
          this.$toast('请输入正确的手机号！')
          return
        }
        if (this.code == '') {
          this.$toast('请输入短信验证码！')
          return
        }
        if (this.password == '') {
          this.$toast('请输入密码！')
          return
        }
        var fkmid = window.localStorage.getItem('fkmid') || this.$route.query.fkmid || this.$utils.getQueryString('fkmid') || ''
        postData.fkmid = fkmid
        if (this.$utils.getDeviceType() == 'wx-iPhone' || this.$utils.getDeviceType() == 'iPhone' || this.member_id) {
          postData.member_id = this.memberInfo.member_id
          this.$request.bindNewMobile1(postData).then(data => {
            this.$toast('操作成功！')
            this.$router.replace({name: 'setting-index'})
          }).catch(e => {
            this.$toast(e.msg)
          })
        } else {
          this.$request.bindNewMobile(postData).then(data => {
            this.$toast('操作成功！')
            this.$router.replace({name: 'setting-index'})
          }).catch(e => {
            this.$toast(e.msg)
          })
        }
      }
    }
  }
</script>

<style>

</style>
